<template>
	<el-dialog v-model="visible" :title="'新增表单'" :close-on-click-modal="false">
		<div>
			<el-button v-auth="'attendance:shift:save'" type="primary" @click="fn()">导出</el-button>
			<h1>创建一个自定义新表单</h1>
		</div>
		<el-row>
			<el-col :span="8">
				<el-card class="layout-home grill-col-home">
					<svg-icon icon="icon-team" class="icon-div" className="icon-svg" size="34px" bColor="rgba(37, 97, 239, 1)" color="#FFFFFF"></svg-icon>
					<p>入职</p>
					<p>用于员工入职申请</p>
				</el-card>
			</el-col>
		</el-row>
		<el-row>
			<el-col> </el-col>
		</el-row>
	</el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus/es'
import { useNewsApi, useNewsSubmitApi } from '@/api/nb/news/news'
import { findListByDictId } from '@/api/nb/business/dictionaries_subset'
import UploadImgView from '@/views/nb_module/image/upload-img-view.vue'
import WangEditor from '@/components/wang-editor/index.vue'

const emit = defineEmits(['refreshDataList'])
const props = defineProps(['code'])

const visible = ref(false)
const dataFormRef = ref()
const fn=()=>{

}

const dataForm = reactive({
	id: '',

	title: '',
	newsBrief: '',
	typeId: '',
	staffId: '',
	imgUrl: '',
	fileUrl: '',
	isTiming: '',
	timingDate: '',
	contentStr: ''
})

const init = (id?: number) => {
	visible.value = true
	dataForm.id = ''

	// 重置表单数据
	if (dataFormRef.value) {
		dataFormRef.value.resetFields()
	}

	if (id) {
		getNews(id)
	}
}

const getNews = (id: number) => {
	useNewsApi(id).then(res => {
		Object.assign(dataForm, res.data)
	})
}

const dataRules = ref({})

// 表单提交
const submitHandle = () => {
	dataFormRef.value.validate((valid: boolean) => {
		if (!valid) {
			return false
		}

		useNewsSubmitApi(dataForm).then(() => {
			ElMessage.success({
				message: '操作成功',
				duration: 500,
				onClose: () => {
					visible.value = false
					emit('refreshDataList')
				}
			})
		})
	})
}

const dictList = ref()
const getDictList = () => {
	findListByDictId({ params: { code: props.code } }).then(res => {
		dictList.value = res.data
	})
}
getDictList()

defineExpose({
	init
})
</script>
